import path from "path"
import { defineConfig } from "vite"
import solidPlugin from "vite-plugin-solid"
import legacy from "@vitejs/plugin-legacy"
import { dynamicBase } from "vite-plugin-dynamic-base"
import vue from "@vitejs/plugin-vue"
import react from "@vitejs/plugin-react"
import { viteStaticCopy } from "vite-plugin-static-copy"
import monacoEditorPlugin from "vite-plugin-monaco-editor"

export default defineConfig({
  resolve: {
    alias: {
      "~": path.resolve(__dirname, "./src"),
      "@solidjs/router": path.resolve(__dirname, "solid-router/src"),
      "solid-icons": path.resolve(__dirname, "node_modules/solid-icons"),
    },
  },
  plugins: [
    vue(),
    solidPlugin(),
    legacy({
      targets: ["defaults"],
    }),
    dynamicBase({
      publicPath: " window.__dynamic_base__",
      transformIndexHtml: true,
    }),
    react(),
  ],
  optimizeDeps: {
    esbuildOptions: {
      format: "esm",
      target: "es2020",
    },
  },
  base: process.env.NODE_ENV === "production" ? "/__dynamic_base__/" : "/",
  build: {
    assetsDir: "assets",
    assetsInlineLimit: 0,
    rollupOptions: {
      output: {},
    },
  },
  server: {
    host: "0.0.0.0",
    fs: {
      strict: false,
    },
    proxy: {
      "/api": {
        target: "http://localhost:5244",
        changeOrigin: true,
      },
    },
  },
})
